{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 超参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_size = 1\n",
    "output_size = 1\n",
    "num_epochs = 60\n",
    "learning_rate = 0.001"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## “玩具”数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train = np.array([[3.3], [4.4], [5.5], [6.71], [6.93], [4.168], \n",
    "                    [9.779], [6.182], [7.59], [2.167], [7.042], \n",
    "                    [10.791], [5.313], [7.997], [3.1]], dtype=np.float32)\n",
    "y_train = np.array([[1.7], [2.76], [2.09], [3.19], [1.694], [1.573], \n",
    "                    [3.366], [2.596], [2.53], [1.221], [2.827], \n",
    "                    [3.465], [1.65], [2.904], [1.3]], dtype=np.float32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 线性回归模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = nn.Linear(input_size, output_size).cuda()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 损失函数和优化器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "criterion = nn.MSELoss()\n",
    "optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 训练模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch [5/60], Loss: 11.9402\n",
      "Epoch [10/60], Loss: 4.9385\n",
      "Epoch [15/60], Loss: 2.1019\n",
      "Epoch [20/60], Loss: 0.9528\n",
      "Epoch [25/60], Loss: 0.4873\n",
      "Epoch [30/60], Loss: 0.2987\n",
      "Epoch [35/60], Loss: 0.2223\n",
      "Epoch [40/60], Loss: 0.1913\n",
      "Epoch [45/60], Loss: 0.1788\n",
      "Epoch [50/60], Loss: 0.1737\n",
      "Epoch [55/60], Loss: 0.1716\n",
      "Epoch [60/60], Loss: 0.1708\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(num_epochs):\n",
    "    # 将Numpy矩阵转为Torch张量\n",
    "    inputs = torch.from_numpy(x_train).cuda()\n",
    "    targets = torch.from_numpy(y_train).cuda()\n",
    "    \n",
    "    # 前向传播\n",
    "    outputs = model(inputs)\n",
    "    loss = criterion(outputs, targets)\n",
    "    \n",
    "    # 反向传播和优化\n",
    "    optimizer.zero_grad()# optimizer.zero_grad()意思是把梯度置零，也就是把loss关于weight的导数变成0.\n",
    "    loss.backward()\n",
    "    optimizer.step()\n",
    "    \n",
    "    if(epoch+1) % 5 == 0:\n",
    "        print('Epoch [{}/{}], Loss: {:.4f}'.format(epoch+1, num_epochs, loss.item()))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 绘制图，保存模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "predicted = model(torch.from_numpy(x_train).cpu().cuda()).cpu().detach().numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl4FFX6NuDnpQMEDIssKgIhUcMSlgQIMMCo7GCCgogj\nI6OjjhMh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niYio/IKh505EROVkyXAXkeYi8pWIbBORrSIyzuyarEREHCLyg4h8ZnYtViIi9UVkgYjsEJHtItLd\n7JqsQkT+5vpd2iIi74hIuNk1mUVE3hKRX0RkS4m2BiKyXER2uT5famaN/mDJcAdQBOAhVY0F8DsA\nY0Qk1uSarGQcgO1mF2FBrwBYpqqtAcSBrxEAQESaAvg/AAmq2g6AA8AIc6sy1VwAgzzaJgJYqaox\nAFa6toOaJcNdVQ+papbr6xNw/pI2NbcqaxCRZgCSAPzD7FqsRETqAbgOwBwAUNXfVPWouVVZShiA\nWiISBqA2gJ9Mrsc0qvo1gF89mocAeNv19dsAhlZpUQFgyXAvSUSiAHQEsN7cSixjBoBHAJw1uxCL\niQaQC+CfrktW/xCRS8wuygpU9SCAFwHsA3AIwDFV/cLcqiznclU95Pr6ZwCXm1mMP1g63EUkAsCH\nAB5Q1eNm12M2ERkM4BdVzTS7FgsKA9AJwCxV7QjgJGzw1tofXNePh8D5H+CVAC4RkT+ZW5V1qXMI\nYdAPI7RsuItIdTiDfb6qfmR2PRbRE8BNIpID4F0AfUTk3+aWZBkHABxQ1XPv8BbAGfYE9AOwV1Vz\nVbUQwEcAephck9UcFpEmAOD6/IvJ9VSaJcNdRATOa6fbVfUls+uxClV9VFWbqWoUnDfEvlRV9sAA\nqOrPAPaLSCtXU18A20wsyUr2AfidiNR2/W71BW82e/oEwJ9dX/8ZwMcm1uIXlgx3OHuod8DZM93g\n+kg0uyiyvLEA5ovIJgDxAKaZXI8luN7NLACQBWAznL/3tnsi01ci8g6AbwG0EpEDIvIXANMB9BeR\nXXC+05luZo3+wCdUiYhsyKo9dyIiqgSGOxGRDTHciYhsiOFORGRDDHciIhtiuBMR2RDDnYjIhhju\nREQ29P8B6ifJ4AeLdPsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22a02b70c18>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x_train, y_train, 'ro', label='Original Line')\n",
    "plt.plot(x_train, predicted, label='Fitted Line')\n",
    "plt.legend()\n",
    "plt.show()\n",
    "\n",
    "# 保存模型检查点\n",
    "torch.save(model.state_dict(), 'model.ckpt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tensorflow-gpu",
   "language": "python",
   "name": "tensorflow-gpu"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
